﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using GISCommon.Business;
using SysCommon;

namespace GISCommon
{
    public partial class RCITS_MapLayer : UserControl
    {
        private ESRI.ArcGIS.Controls.AxMapControl mapCtrl;
        public RCITS_MapLayer()
        {
            InitializeComponent();
            tv_MapLayer.AfterCheck += new TreeViewEventHandler(tv_MapLayer_AfterCheck);
        }

        void tv_MapLayer_AfterCheck(object sender, TreeViewEventArgs e)
        {
            try
            {
                string layerName = e.Node.Text;
                for (int i = 0; i < mapCtrl.LayerCount; i++)
                {
                    ILayer ly = mapCtrl.get_Layer(i);
                    if (layerName != ly.Name) continue;
                    ly.Visible = e.Node.Checked;
                    mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, ly, null);
                    break;
                }
            }
            catch(Exception ex)
            {
                Global.mainLog.Error("调用 tv_MapLayer_AfterCheck 方法出错", ex);
            }
        }

        public void init(ESRI.ArcGIS.Controls.AxMapControl inMapCtrl)
        {
            mapCtrl = inMapCtrl;
            string m_name = "图层信息";
            for (int i = 0; i < mapCtrl.LayerCount; i++)
            {
                m_name += "," + mapCtrl.get_Layer(i).Name;
            }

            SysCommon.Tools.TreeViewHelper.BindTreeView(tv_MapLayer, m_name);
            //map_Layer = new AxTOCControl();
            //map_Layer.Width = this.Width;
            //map_Layer.Height = this.Height;
            //map_Layer.Dock = DockStyle.Fill;

            //ESRI.ArcGIS.Carto.IMap m_map = new ESRI.ArcGIS.Carto.Map();
            //m_map = mapCtrl.Map;
            //m_map.Expanded = false;


            //mapCtrl.Map.Expanded = true;   

            //this.Controls.Add(map_Layer);
            //map_Layer.SetBuddyControl(mapCtrl);
            
        }

        //private ESRI.ArcGIS.TOCControl.AxTOCControl map_Layer = null;
        //public AxTOCControl RCITSMapLayerCtrl
        //{
        //    set { map_Layer = value; }
        //    get { return map_Layer; }
        //}
    }
}
